#include <iostream>

using namespace std;

double arctan(double x)
{
    double e = x;
    double r = 0;
    double sqr = x * x;
    int i = 1;
    while (e / i > 1e-15){
        double f = e / i;
        r = (i % 4 == 1)? r + f: r - f;//判断是加还是减
        e = e * sqr;
        i += 2;
    }
    return r;
}


int main()
{
    double a = 16.0 * arctan(1/5.0);//调用函数，注意数据类型
    double b = 4.0 * arctan(1/239.0);

    cout << "PI = " << a - b << endl;
    return 0;
}
